/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package forensicsGUI.api;

import forensicsGUI.ErrorInstanceLogger;
import forensicsGUI.GuiNotification;
import forensicsGUI.InstanceLogger;
import forensicsGUI.ProgramState;
import java.io.File;
import java.io.Serializable;
import java.util.Vector;

/**
 *
 * @author marc
 */
public abstract class forensicsInstance implements Serializable, Runnable {
    // details for this instance

    protected Vector<String> imageLocations = null;
    protected String investigatorName = "";
    protected String caseDetails = "";
    protected String caseNumber = "";
    protected String executableLocation = "";
    protected String executable = "";
    protected String outputDir = "";
    protected boolean executed = false;
    protected boolean finished = false;
    protected InstanceLogger outputLogger = new InstanceLogger();
    protected ErrorInstanceLogger errorLogger = new ErrorInstanceLogger();
    protected ProgramState currentState = null;


    /**
     * Returns the executable location.
     * @return
     */
    public String getExecutableLocation()
    {
        return executableLocation;
    }
    /**
     * Returns the output logger.
     * @return
     */
    public InstanceLogger getOutputLogger()
    {
        return outputLogger;
    }

    /**
     * Returns the error logger.
     * @return
     */
    public ErrorInstanceLogger getErrorLogger()
    {
        return errorLogger;
    }

    /**
     * Returns the current state.
     * @return
     */
    public ProgramState getProgramState()
    {
        return currentState;
    }


    /**
     * Sets the program state variable.
     * @param state
     */
    public void setProgramState(ProgramState state) {
        currentState = state;
    }

    /**
     * Returns a boolean value indicating whether or not this instance
     * has executed.
     * @return
     */
    public boolean hasExecuted() {
        return executed;
    }

    /**
     * Returns a boolean value indicating whether or not this instance
     * has finished.
     * @return
     */
    public boolean hasFinished() {
        return finished;
    }

    /**
     * Returns the case number for this instance.
     * @return case number
     */
    public String getCaseNumber() {
        return caseNumber;
    }

    /**
     * Sets the case number for this instance.
     * @param caseNumber
     */
    public void setCaseNumber(String caseNumber) {
        this.caseNumber = caseNumber;
    }

    /**
     * Return case details.
     * @return
     */
    public String getCaseDetails()
    {
        return caseDetails;
    }

    /**
     * Sets the case details for this instance.
     * @param caseDetails
     */
    public void setCaseDetails(String caseDetails) {
        this.caseDetails = caseDetails;
    }

    /**
     * Returns the investigator's name
     * @return
     */
    public String getInvestigatorName()
    {
        return investigatorName;
    }
    /**
     * Sets the investigator's name for this instance.
     * @param investigatorName
     */
    public void setInvestigatorName(String investigatorName) {
        this.investigatorName = investigatorName;
    }

    /**
     * Sets the executable name for this instance.
     * @param exec
     */
    public void setExec(String exec) {
        executable = exec;
    }

    /**
     * Sets the execution list.
     * @param list
     */
    public void setExecList(Vector<String> list) {
        imageLocations = list;
    }

    /**
     * Sets the execution location for the executable.
     * @param exec
     */
    public void setExecLocation(String exec) {
        executableLocation = exec;
    }

    /**
     * Sets the out directory
     * @return
     */
    public String getOutputDir() {
        return outputDir;
    }

    /**
     * Sets the output directory
     * @param output
     */
    public void setOutput(String output) {
        outputDir = output;
        if (outputDir.lastIndexOf("/") == outputDir.length() - 1) {
            outputDir = outputDir.substring(0, outputDir.length() - 1);
        }

        if (caseNumber.length() > 0) {
            outputDir = outputDir + "/output_" + caseNumber;
        } else {
            outputDir = outputDir + "/output";
        }
        String outputcheck = "";
        int i = 0;
        for (; i < 100; i++) {
            outputcheck = outputDir;
            if (i > 0) {
                outputcheck += "_" + i;
            }
            File file = new File(outputcheck + "/");
            boolean exists = file.exists();
            if (!exists) {
                outputDir = outputcheck;
                break;
            }
        }
        if (i == 100) {
            GuiNotification.displayNotification(
                    "Cannot create an output directory, cannot continue",
                    "Foremost Error", GuiNotification.ERROR);

        }
    }
}
